﻿@{
    ViewBag.Title = "自动货机首页";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Styles.Render("~/Content/css/home")
<header id="homeTitle" class="Index"></header>
<section id="venderLayout" style="display:none"></section>
<section id="noVenderLayout" class="noVenderLayout" style="display:none"></section>

<script>
    window.onload = function () {
        UserInfoMgr.setOpenId('@ViewBag.OpenId', function (openId) {
            if (openId == null || openId == "") {
                venderDialog("获取用户信息失败，请关闭浏览器稍后重试。");
            } else {
                UserInfoMgr.weixinLogin(null, null);
            }
        });
        TerminalMgr.getMainMenuList(showTerminal, showNoTerminal);
    }

    function showTerminal() {
        loadTitle();
        $("#venderLayout").show();
        $("#noVenderLayout").hide();
        var url = '/Home/VenderLayout';
        NativeAjax(null, url, function (msg) {
            loadPartialViewResult(msg, $("#venderLayout"), 1);
        });
    }

    function showNoTerminal() {
        loadTitle();
        $("#noVenderLayout").show();
        $("#venderLayout").hide();
        var url = '/Home/NoVenderLayout';
        NativeAjax(null, url, function (msg) {
            loadPartialViewResult(msg, $("#noVenderLayout"), 1);
        });
    }

    function goLocation() {
        window.location.href = '/Location/Index';
    }

    function goUserCenter() {
        var isLog = UserInfoMgr.isLogIn();
        if (isLog) {
            window.location.href = '/UserCenter/Index';
        } else {
            window.location.href = spliceRegisterUrl('/UserCenter/Index', '/Home/Index');
        }
    }

    function loadTitle() {
        var addressName = AddressMgr.getCurName();
        var $div = $(
            '<div class=\"IndexHead\">'
            + '<a class=\"IndexHeadFl fll\" onclick=\"goLocation()\">'
            + '<span>' + addressName + '</span><img src=\"/images/addr_click.png">'
            + '</a>'
            + '<a onclick=\"goUserCenter()\" class=\"IndexHeadFr flr\"><img src=\"/images/user_normal.png\" ontouchstart=\"userInfoHover(this, 1)\" ontouchend=\"userInfoHover(this, 0)\"></a>'
            + '</div>');
        $("header#homeTitle").append($div);
    }
</script>